package com.wangjiacai.hqlQuery.repository.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import javax.persistence.Query;

public class EntityManagerBaseRepositoryImpl extends AbstracterBaseRepositoryImpl {

    @Autowired
    private EntityManager entityManager;

    public EntityManagerBaseRepositoryImpl(){

    }

    public EntityManagerBaseRepositoryImpl(EntityManager entityManager){
        this.entityManager=entityManager;
    }

    @Override
    Query createQuery(String hql) {
        return entityManager.createQuery(hql);
    }

    @Override
    Query createNativeQuery(String sql) {
        return entityManager.createNativeQuery(sql);
    }

    @Override
    @Transactional
    public <T> T save(T t) {
        entityManager.merge(t);
        return t;
    }
}
